package Project2.cs342.project1.mathNotebook.notebook;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

/**
 * Abstract table for the slope table in user interface
 * @author Alejandro Carrasquill
 */
public class SlopeTable extends AbstractTableModel{
	
	public NotebookEntry entry = null;
	public List<List<Double>> slopeT = null;
	
	
	
	public SlopeTable(NotebookEntry entry){
		this.entry = entry;
		slopeT = new ArrayList<List<Double>>();
		slopeT.add(new ArrayList<Double>());
		slopeT.add(new ArrayList<Double>());
	
		for (Double tangentPoint : entry.tangentPoints) {
			slopeT.get(0).add(tangentPoint);
			slopeT.get(1).add(roundTwoDecimals(NotebookEntry.findSlopeAt(entry.function,tangentPoint)));
		}
	}

	double roundTwoDecimals(double d) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        return Double.valueOf(twoDForm.format(d));
    }
	
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return entry.tangentPoints.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		return slopeT.get(columnIndex).get(rowIndex);
	}
	
	public boolean isCellEditable(int rowIndex, int colIndex){
		return true;
	}
	
	public void setValueAt(Object obj, int row, int column){
		
	}
	
}
